﻿using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace Dynamic.Data.Model.Query
{
    [DataContract]
    [XmlType(Namespace = "DynamicMatrix"), XmlInclude(typeof(QueryExpression)), XmlInclude(typeof(QueryByAttribute))]
    public abstract class QueryBase
    {
        private ColumnSetBase _columnSet;
        private string _entityName;
        private bool _isCascade = false;

        public QueryBase()
        {
        }

        public QueryBase(string entityName)
        {
            this._entityName = entityName;
            this._columnSet = new ColumnSet(entityName);
        }

        public abstract void Accept(IQueryVisitor visitor);

        [DataMember]
        public ColumnSetBase ColumnSet
        {
            get
            {
                return this._columnSet;
            }
            set
            {
                this._columnSet = value;
                if ((this._columnSet is ColumnSet) && (((ColumnSet)this._columnSet).EntityName == null))
                {
                    ((ColumnSet)this._columnSet).EntityName = this.EntityName;
                }
            }
        }

        [DataMember]
        public string EntityName
        {
            get
            {
                return this._entityName;
            }
            set
            {
                this._entityName = value;
            }
        }

        [DataMember]
        public bool IsCascade
        {
            get
            {
                return this._isCascade;
            }
            set
            {
                this._isCascade = value;
            }
        }
    }
}

